package com.laoyao.util;

import java.beans.Statement;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class DownloadPicture {  
	  
   /* public static void main(String[] args) {  
        DownloadPicture downloadPicture = new DownloadPicture();  
        ArrayList<String> urlList = new ArrayList<String>();
        String url = "https://a1.easemob.com/1175170222178487/tang/chatfiles/94ca33e0-0e0e-11e7-9aa3-2395c67ea2a1";
        urlList.add(url);
        downloadPicture.downloadPicture(urlList);
    } */ 
  
    /** 
     * ����Ҫ���ص�ͼƬ��url�б?��url���Ӧ��ͼƬ���ص����� 
     * @param urlList 
     */  
    public void downloadPicture(ArrayList<String> urlList , String path) {  
        URL url = null;  
          
        for (String urlString : urlList) {  
            try {  
                url = new URL(urlString);  
                DataInputStream dataInputStream = new DataInputStream(url.openStream());  
                String imageName = path + ".jpg";  
                FileOutputStream fileOutputStream = new FileOutputStream(new File(imageName));  
  
                byte[] buffer = new byte[1024];  
                int length;  
  
                while ((length = dataInputStream.read(buffer)) > 0) {  
                    fileOutputStream.write(buffer, 0, length);  
                }  
  
                dataInputStream.close();  
                fileOutputStream.close();  
            } catch (MalformedURLException e) {  
                e.printStackTrace();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
    }  
  
}  